package com.qxp.simplerpc;

import com.qxp.simplerpc.annotation.EnableSimpleRpcAutoConfig;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnBean(annotation= EnableSimpleRpcAutoConfig.class)
@ConditionalOnProperty(prefix="spring.simplerpc.registry",value = "address")
public class RegistryAutoConfiguration extends CommonAutoConfiguration {
    @Bean
    public RegistryService getRegisterService(){
        String registryType = getSimpleRpcProperties().getRegistry().getType();
        switch (registryType){
            case "redis" :
                return new RedisRegistryServiceImpl();
            case "zookeeper":
                return new ZookeeperRegisterServiceImpl();
            default:
                return null;
        }
    }
}
